<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="流程" prop="flowtempId">
        <el-select placeholder="请选择流程" clearable v-model="flowtempId" size="small" @change="getFlowtemp">
          <el-option
            v-for="dict in flowtempOptions"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="节点名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入节点名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['flow:flowtempnode:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['flow:flowtempnode:edit']"
        >修改
        </el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['flow:flowtempnode:remove']"-->
<!--        >删除-->
<!--        </el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['flow:flowtempnode:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          icon="el-icon-refresh-right"
          size="mini"
          @click="handleRefresh"
        >重新加载流程配置
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="flowtempnodeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!-- <el-table-column label="流程" align="center" prop="flowtempname"/> -->
      <!-- <el-table-column label="节点编码" align="center" prop="code" /> -->
      <el-table-column label="节点名称" align="center" prop="name"/>
      <!-- <el-table-column label="下一节点编号" align="center" prop="nextcode" /> -->
      <!--      <el-table-column label="抄送通知" align="center" prop="msgtempid">
              <template slot-scope="scope">
                <span>{{scope.row.nrulename}} {{scope.row.nwxmodelname}}</span>
              </template>
            </el-table-column>-->
      <el-table-column label="操作标识" align="center" prop="operate"/>
      <el-table-column label="权限" align="center" prop="permissionname">
        <template slot-scope="scope">
          <span v-if="scope.row.permission == 0">发起人</span>
          <span v-if="scope.row.permission != 0">{{ scope.row.permissionname }}</span>
        </template>
      </el-table-column>
      <el-table-column label="当前状态" align="center" prop="nowstatusname"/>
      <el-table-column label="下一状态" align="center" prop="nextstatusname"/>
      <el-table-column label="下一节点" align="center" prop="nextnodaname"/>
      <el-table-column label="排序" align="center" prop="sort"/>
      <!-- <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="附件是否必填" align="center" prop="annex"/>-->
      <el-table-column label="会签类型" align="center" prop="approvalType">
        <template slot-scope="scope">
          <span v-if="scope.row.approvalType == 1">串行节点</span>
          <span v-if="scope.row.approvalType == 2">并发主</span>
          <span v-if="scope.row.approvalType == 3">并发子</span>
        </template>
      </el-table-column>
      <el-table-column label="会签编号" align="center" prop="branchiids"/>
      <!--      <el-table-column label="节点类型" align="center" prop="nodetype" :formatter="nodetypeFormat" />
            <el-table-column label="展示标识" align="center" prop="flag">
              <template slot-scope="scope">
                <span v-if="scope.row.flag == 1">主流程</span>
              </template>
            </el-table-column>
      &lt;!&ndash;      <el-table-column label="是否发起OA" align="center" prop="issendoa">
              <template slot-scope="scope">
                <span v-if="scope.row.issendoa == 1">是</span>
                <span v-if="scope.row.issendoa == 2">否</span>
              </template>
            </el-table-column>&ndash;&gt;
             <el-table-column label="是否可回退" align="center" prop="repeatflag">
              <template slot-scope="scope">
                <span v-if="scope.row.repeatflag == 1">是</span>
                <span v-if="scope.row.repeatflag == 2">否</span>
              </template>
            </el-table-column>
            <el-table-column label="拒绝标识" align="center" prop="refuseflag">
              <template slot-scope="scope">
                <span v-if="scope.row.refuseflag == 1">允许</span>
                <span v-if="scope.row.refuseflag == 2">否</span>
              </template>
            </el-table-column>
            <el-table-column label="是否发送待处理通知" align="center" prop="sendtodomsgflag">
              <template slot-scope="scope">
                <span v-if="scope.row.sendtodomsgflag == 1">发送</span>
                <span v-if="scope.row.sendtodomsgflag == 2">不发送</span>
              </template>
            </el-table-column>
           -->
      <!-- <el-table-column label="办理时限(分钟)" align="center" prop="timeLimit" />
      <el-table-column label="催办内容" align="center" prop="reminderMsg" />
      <el-table-column label="督办人" align="center" prop="supervisor" />
      <el-table-column label="督办消息发送规则" align="center" prop="remindRule" />
      <el-table-column label="操作" align="center" prop="operation" /> -->

      <!-- <el-table-column label="最终节点" align="center" prop="finalnodeids" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['flow:flowtempnode:edit']"
          >修改
          </el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['flow:flowtempnode:remove']"-->
<!--          >删除-->
<!--          </el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-top"
            @click="handleCon(scope.row)"
            v-hasPermi="['flow:flowconditions:query']"
          >条件
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改流程节点对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1210px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px" :inline="true">
        <el-form-item label="流程" prop="flowtempname">
          <el-select v-model="form.flowtempId" placeholder="请选择流程" size="small" filterable>
            <el-option
              v-for="dict in flowtempOptions"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
              @click.native="getStatus($event, dict)">
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="节点编码" prop="code">
          <el-input v-model="form.code" placeholder="请输入节点编码" size="small" clearable/>
        </el-form-item> -->
        <el-form-item label="节点名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入节点名称" size="small" clearable/>
        </el-form-item>
        <!-- <el-form-item label="下一节点" prop="nextcode">
          <el-input v-model="form.nextcode" placeholder="请输入下一节点编号" size="small" clearable/>

        </el-form-item> -->
        <el-form-item label="抄送通知" prop="ccPerm">
          <el-input v-model="form.ccPerm" placeholder="请输入抄送通知" size="small" clearable filterable>
            <!--            <el-option-->
            <!--              v-for="dict in smsrulwOptions"-->
            <!--              :key="dict.guid"-->
            <!--              :label="dict.typename + dict.wxmodelname"-->
            <!--              :value="dict.guid"-->
            <!--            ></el-option>-->
          </el-input>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" size="small" clearable/>
        </el-form-item>
        <el-form-item label="操作标识" prop="operate">
          <el-input v-model="form.operate" placeholder="请输入操作标识" size="small" clearable/>
        </el-form-item>
        <el-form-item label="操作权限" prop="permission">
          <el-select v-model="form.permission" placeholder="请选择流程操作权限" size="small" filterable clearable>
            <el-option
              v-for="dict in defOptions"
              :key="dict.code"
              :label="dict.name"
              :value="parseInt(dict.code)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="当前状态" prop="nowstatusname">
          <el-select v-model="form.flowStat" placeholder="请选择流程当前状态值" size="small" filterable>
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="下一状态" prop="nextstatusname">
          <el-select v-model="form.flowNextStat" placeholder="请选择流程下一状态值" size="small" filterable>
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="下一节点" prop="nextnodaname">
          <el-select v-model="form.nextNodeId" placeholder="请选择下一节点" size="small" filterable>
            <el-option
              v-for="dict in nodeOptions"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="节点类型" prop="nodeType">
          <el-select v-model="form.nodeType" placeholder="请选择节点类型" size="small">
            <el-option
              v-for="dict in nodetypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="展示标识" prop="flag">
          <!-- <el-input v-model="form.flag" placeholder="请输入主流程标识1-主流程" size="small" clearable/> -->
          <el-select v-model="form.flag" placeholder="是否在审批记录中展示该节点" size="small" clearable>
            <el-option label="主流程" value="1">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否发起OA" prop="isSendOa">
          <el-input v-model="form.isSendOa" placeholder="请输入是否发起OA" size="small" clearable>
            <!--            <el-option key="1" label="是" value="1" />-->
            <!--            <el-option key="2" label="否" value="2" />-->
          </el-input>
        </el-form-item>
        <el-form-item label="是否可回退" prop="repeatFlag">
          <el-select v-model="form.repeatFlag" placeholder="拒绝回退时是否可跨过本节点" size="small" clearable>
            <el-option key="1" label="是" value="1"/>
            <el-option key="2" label="否" value="2"/>
          </el-select>
        </el-form-item>
        <el-form-item label="是否可拒绝" prop="refuseFlag">
          <el-select v-model="form.refuseFlag" placeholder="请选择是否可拒绝" size="small" clearable>
            <el-option key="1" label="允许" value="1"/>
            <el-option key="2" label="否" value="2"/>
          </el-select>
        </el-form-item>
        <!--        <el-form-item label="是否发通知" prop="sendtodomsgflag">-->
        <!--          <el-select v-model="form.sendtodomsgflag" placeholder="是否发送待处理通知" size="small" clearable>-->
        <!--            <el-option key="1" label="发送" value="1" />-->
        <!--            <el-option key="2" label="不发送" value="2" />-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <el-form-item label="办理时限(分钟)" prop="timeLimit">
          <el-input v-model="form.timeLimit" placeholder="请输入办理时限(分钟)" size="small" clearable/>
        </el-form-item>
        <!-- <el-form-item label="催办内容" prop="reminderMsg">
          <el-input v-model="form.reminderMsg" placeholder="请输入催办内容" size="small" clearable/>
        </el-form-item> -->

        <!--        <el-form-item label="督办人" prop="supervisor">-->
        <!--          &lt;!&ndash; <el-input v-model="form.supervisor" placeholder="请输入督办人" size="small" clearable/> &ndash;&gt;-->
        <!--          <el-select v-model="form.nickName" placeholder="选择督办人" size="small" clearable filterable multiple>-->
        <!--            <el-option-->
        <!--              v-for="item in tuserOptions"-->
        <!--              :key="item.userId"-->
        <!--              :label="item.nickName"-->
        <!--              :value="item.userId"-->
        <!--            />-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->

        <el-form-item label="催办消息规则" prop="remindRule">
          <el-input v-model="form.remindRule" placeholder="催办间隔及次数，如:10,3" size="small" clearable/>
        </el-form-item>
        <el-form-item label="通知操作提示" prop="operation">
          <el-input v-model="form.operation" placeholder="请输入通知消息操作提示" size="small" clearable/>
        </el-form-item>
        <el-form-item label="会签节点类型" prop="approvalType">
          <el-select v-model="form.approvalType" placeholder="请选择会签节点类型" size="small">
            <el-option key="1" label="串行节点" value="1"/>
            <el-option key="2" label="并发主" value="2"/>
            <el-option key="3" label="并发子" value="3"/>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="最终节点" prop="finalnodeids">
          <el-input v-model="form.finalnodeids" placeholder="请输入最终节点" size="small" clearable/>
        </el-form-item> -->
        <el-form-item label="分支编号" prop="branchiids">
          <el-input v-model="form.branchiids" placeholder="请输入分支编号" size="small" clearable/>
        </el-form-item>

        <el-form-item label="自动通过" prop="annex">
          <el-input v-model="form.annex" placeholder="请输入是否自动通过" size="small" clearable/>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" size="small" clearable/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--条件页面展示-->
    <el-dialog title="流程条件" :visible.sync="openCon" width="1000px" append-to-body>
      <el-button type="primary" @click="conditionsadd">新增</el-button>
      <el-table v-loading="loading" :data="conData">
        <el-table-column label="说明" align="center" prop="remark" width="280px">
          <!-- <template slot-scope="{row,$index}">
            <span v-if="!showEdit[$index]">{{row.remark}}</span>
            <el-input type="text" v-model="row.remark" v-else placeholder="请输入说明"></el-input>
          </template> -->
        </el-table-column>
        <el-table-column label="流程条件" align="center" prop="conditions" width="280px">
          <!-- <template slot-scope="{row,$index}">
            <span v-if="!showEdit[$index]">{{row.conditions}}</span>
            <el-input type="text" v-model="row.conditions" v-else placeholder="请输入流程条件"></el-input>
          </template> -->
        </el-table-column>
        <el-table-column label="流程下一节点" align="center" prop="nexrnodename" width="100px"/>
        <el-table-column label="流程下一状态" align="center" prop="statusname" width="100px">
          <!-- <template slot-scope="{row,$index}">
            <span v-if="!showEdit[$index]">{{row.flownextstat}}</span>
            <el-input type="text" v-model="row.flownextstat" v-else placeholder="请输入流程下一状态"></el-input>
          </template> -->
        </el-table-column>

<!--        <el-table-column label="是否发起OA审批" align="center" prop="issendoa">-->
<!--          &lt;!&ndash;        <template slot-scope="scope">&ndash;&gt;-->
<!--          &lt;!&ndash;           <span v-if="scope.row.issendoa == 1">是</span>&ndash;&gt;-->
<!--          &lt;!&ndash;            <span v-if="scope.row.issendoa == 2">否</span>&ndash;&gt;-->
<!--          &lt;!&ndash;        </template>&ndash;&gt;-->
<!--        </el-table-column>-->
<!--        <el-table-column label="抄送通知" align="center" prop="ccPerm">-->
<!--          &lt;!&ndash; <template slot-scope="{row,$index}">-->
<!--            <span v-if="!showEdit[$index]">{{row.msgtempid}}</span>-->
<!--            <el-input type="text" v-model="row.msgtempid" v-else placeholder="请输入通知模板id"></el-input>-->
<!--          </template> &ndash;&gt;-->
<!--        </el-table-column>-->

        <!--      <el-table-column label="流程" align="center" prop="tempname" />-->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdateCon(scope.row)"
              v-hasPermi="['flow:flowconditions:edit']"
            >修改
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDeleteCon(scope.row)"
              v-hasPermi="['flow:flowconditions:remove']"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!--    条件新增或修改页面-->
    <el-dialog title="流程条件" :visible.sync="openEditCon" width="800px" append-to-body>
      <el-form ref="formCon" :model="formCon" :rules="rules" label-width="120px">
        <!--        <el-form-item label="节点id" prop="nodeguid" v-show="false">-->
        <!--          <el-input v-model="formCon.nodeguid" placeholder="请输入节点id" />-->
        <!--        </el-form-item>-->
        <el-form-item label="说明" prop="remark">
          <el-input v-model="formCon.remark" placeholder="请输入说明"/>
        </el-form-item>
        <el-form-item label="流程条件" prop="conditions">
          <el-input v-model="formCon.conditions" placeholder="请输入流程条件"/>
        </el-form-item>
        <el-form-item label="流程下一节点" prop="nextNodeId">
          <!-- <el-input v-model="formCon.nextnodeid" placeholder="请输入流程下一节点id" /> -->
          <el-select v-model="formCon.nextNodeId" placeholder="请选择下一节点" clearable>
            <el-option
              v-for="dict in nodeOptions"
              :key="dict.id"
              :label="dict.name"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="流程下一状态" prop="flownextstat">
          <!-- <el-input v-model="formCon.flownextstat" placeholder="请输入流程下一状态" /> -->
          <el-select v-model="formCon.flownextstat" placeholder="请选择流程下一状态">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否发起OA审批" prop="issendoa">
          <el-input v-model="formCon.issendoa" placeholder="请输入是否发起审批" clearable>
            <!--            <el-option key="1" label="是" value="1" />-->
            <!--            <el-option key="2" label="否" value="2" />-->
          </el-input>
        </el-form-item>
        <el-form-item label="抄送通知" prop="ccPerm">
          <!-- <el-input v-model="formCon.msgtempid" placeholder="请输入通知模板id" /> -->
          <el-input v-model="formCon.ccPerm" placeholder="请输入抄送通知" clearable>
            <!--            <el-option-->
            <!--              v-for="dict in smsrulwOptions"-->
            <!--              :key="dict.rulecode"-->
            <!--              :label="dict.typename + dict.wxmodelname"-->
            <!--              :value="dict.rulecode"-->
            <!--            ></el-option>-->
          </el-input>
        </el-form-item>

        <el-form-item label="流程id" prop="flowtempid" v-show="false">
          <el-input v-model="formCon.flowtempid" placeholder="请输入流程id"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormCon">确 定</el-button>
        <el-button @click="cancelCon">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import {
  listFlowtempnode,
  getFlowtempnode,
  delFlowtempnode,
  addFlowtempnode,
  updateFlowtempnode,
  exportFlowtempnode,
  allNeedReload,
  getFlowtempnodeInFo
} from "@/api/flow/flowtempnode";
import {
  listFlowconditions,
  getFlowconditions,
  delFlowconditions,
  addFlowconditions,
  updateFlowconditions,
  exportFlowconditions
} from "@/api/flow/flowconditions";
import {
  getFlowtemp,
  getSmsrule,
  getPermissionDeflist,
  getDict,
  getFlowtempnodeBy,
  tuserList,
  getUserList
} from "@/api/public"
import {getDicts} from "@/api/system/dict/data";

export default {
  name: "Flowtempnode",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      busistatdicks: [],
      flowtempids: [],
      flowtempId: "",
      // 非单个禁用
      single: true,

      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 流程节点表格数据
      flowtempnodeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 流程字典
      flowtempidOptions: [],
      // 分类字典
      annexOptions: [],
      // 节点类型字典
      nodetypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        flowtempId: null,
        code: null,
        name: null,
      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {
        flowtempId: [
          {required: true, message: "流程不能为空", trigger: "change"}
        ],
        name: [
          {required: true, message: "节点名称不能为空", trigger: "blur"}
        ],
        operate: [
          {required: true, message: "操作标识不能为空", trigger: "blur"}
        ],
        // permission: [
        //   {required: true, message: "操作权限不能为空", trigger: "blur"}
        // ],
        flowNextStat: [
          {required: true, message: "流程下一状态值不能为空", trigger: "blur"}
        ],
        flowStat: [
          {required: true, message: "流程当前状态值不能为空", trigger: "blur"}
        ],
        nodeType: [
          {required: true, message: "节点类型不能为空", trigger: "change"}
        ],
        approvalType: [
          {required: true, message: "会签节点类型不能为空", trigger: "change"}
        ],
        nextNodeId: [
          {required: true, message: "流程下一节点不能为空", trigger: "blur"}
        ],
        flownextstat:[
          {required: true, message: "流程下一状态不能为空", trigger: "blur"}
        ],
        repeatFlag:[
          {required: true, message: "是否可回退不能为空", trigger: "blur"}
        ],
      },
      openCon: false,
      conData: [],
      nodeguid: null,
      nodeId: null,
      showEdit: [],
      conditions: [],
      openEditCon: false,
      formCon: {},
      flowtempOptions: [],
      smsrulwOptions: [],
      defOptions: [],
      statusOptions: [],
      nodeOptions: [],
      tuserOptions: [],
      flowtempnodeRow: {},
    };
  },
  watch: {
    'form.flowNextStat': function (val, oldVal) {
      this.form.flowNextStat = val;
    },
    'form.flowStat': function (val, oldVal) {
      this.form.flowStat = val;
    },
    'form.nextNodeId': function (val, oldVal) {
      // console.log("nextNodeId=val:"+val,"old:"+oldVal);
      this.form.nextNodeId = val;
    },
    'form.flowtempId': function (val, valOld) {
      this.form.flowtempId = val;
      // console.log("flowtempid=val:"+val,"old:"+valOld);
    },
    'formCon.flowtempid': function (val, valOld) {
      this.formCon.flowtempid = val;
      // console.log("formCon:flowtempid=val:"+val,"old:"+valOld);
    }

  },

  created() {
    //this.getList();
    this.getFlowtemp();
    this.getSmsrule();
    this.getPermissionDeflist();
    this.getUserList();
    this.getDicts("flow_temp").then(response => {
      this.flowtempidOptions = response.data;
    });
    this.getDicts("flow_annex").then(response => {
      this.annexOptions = response.data;
    });
    this.getDicts("node_type").then(response => {
      this.nodetypeOptions = response.data;
    });
  },

  methods: {
    getStatus(event, item) {
      console.log(item.busistatdick)
      if (item.busistatdick != null) {
        this.getDicts(item.busistatdick).then(response => {
          this.statusOptions = response.data;
        });
      }

      getFlowtempnodeBy({flowtempId: item.id}).then(response => {
        this.nodeOptions = response.data;
      });
    },
    getUserList() {
      getUserList().then(response => {
        this.tuserOptions = response.data;
      });
    },
    getPermissionDeflist() {
      getPermissionDeflist().then(response => {
        this.defOptions = response.data;
        let me = {};
        me.code = "0";
        me.name = "发起人";
        this.defOptions.push(me);
        // console.log(this.defOptions)
      });
    },
    getSmsrule() {
      getSmsrule().then(response => {
        this.smsrulwOptions = response.data;
      });
    },
    getFlowtemp() {
      getFlowtemp().then(response => {
        this.flowtempOptions = response.data;
      });
    },
    /** 查询流程节点列表 */
    getList() {
      if (this.flowtempId == null) {
        // console.log(this.queryParams.flowtempId)
        this.msgError("请选择一个流程");
        return
      }
      this.loading = true;
      this.queryParams.flowtempId = this.flowtempId;
      // console.log(this.queryParams);
      listFlowtempnode(this.queryParams).then(response => {
        // console.log(this.flowtempId);
        // console.log(this.queryParams);
        this.flowtempnodeList = response.rows;
        // console.log(this.flowtempnodeList);
        this.total = response.total;
        this.loading = false;
      });
    },
    // 流程字典翻译
    flowtempidFormat(row, column) {
      return this.selectDictLabel(this.flowtempidOptions, row.flowtempId);
    },
    // 分类字典翻译
    annexFormat(row, column) {
      return this.selectDictLabel(this.annexOptions, row.annex);
    },
    // 节点类型字典翻译
    nodetypeFormat(row, column) {
      return this.selectDictLabel(this.nodetypeOptions, row.nodeType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        guid: null,
        flowtempId: null,
        code: null,
        name: null,
        nextcode: null,
        nextNodeId: null,
        msgtempid: null,
        operate: null,
        permission: null,
        flowNextStat: null,
        flowStat: "",
        repeatFlag: null,
        sort: null,
        remark: null,
        annex: null,
        nodeType: null,
        flag: "",
        isSendOa: null,
        refuseFlag: null,
        refusemsgid: null,
        sendtodomsgflag: null,
        nextnodeid: null,
        timeLimit: null,
        reminderMsg: null,
        // supervisor: null,
        remindRule: null,
        operation: null,
        approvalType: null,
        finalnodeids: null,
        branchiids: null
      };
      this.resetForm("form");
    },
    resetCon() {
      this.formCon = {
        id: null,
        guid: null,
        nodeguid: null,
        nodeId: null,
        conditions: null,
        flowNextStat: null,
        remark: null,
        isSendOa: "",
        issendoa: "",
        msgtempid: null,
        nextnodeid: null,
        nextNodeId: null,
        flowtempId: null,
        flowtempid: null,
        ccPerm: null,
        nexrnodename: null
      }
      this.resetForm("formCon");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.busistatdicks = selection.map(item => item.busistatdick)
      this.flowtempids = selection.map(item => item.flowtempId)
      this.flowtempId = this.flowtempids[0];
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加流程节点";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      const busistatdick = row.busistatdick || this.busistatdicks
      const flowtempId = row.flowtempId || this.flowtempId
      // console.log(id);
      console.log('before-',this.form)
      getFlowtempnodeInFo(id).then(response => {
        console.log('response:',response)
        this.form = response.data;
        console.log('form--',this.form);
        // this.form.flowstat=response.data.flowstat;
        this.form.approvalType = response.data.approvalType + '';
        // console.log(response.data);

        // if (this.form.annex != null && this.form.annex != "") {
        //   this.form.annex = this.form.annex.split(",")
        // }
        // if(this.form.supervisor != null && this.form.supervisor != ""){
        //   this.form.supervisor = this.form.supervisor.split(",")
        // }

        if (this.form.flag != null) {
          this.form.flag = this.form.flag.toString();
        }
        if (this.form.refuseFlag != null) {
          this.form.refuseFlag = this.form.refuseFlag.toString();
        }
        if (this.form.isSendOa != null) {
          this.form.isSendOa = this.form.isSendOa.toString();
        }
        if (this.form.repeatFlag != null) {
          this.form.repeatFlag = this.form.repeatFlag.toString();
        }
        if (this.form.sendtodomsgflag != null) {
          this.form.sendtodomsgflag = this.form.sendtodomsgflag.toString();
        }
        if (this.form.approvalType != null) {
          this.form.approvalType = this.form.approvalType.toString();
        }
        if (this.form.permission != null) {
          this.form.permission = parseInt(this.form.permission);
        }

        this.getDicts(busistatdick).then(response => {
          this.statusOptions = response.data;
        });

        getFlowtempnodeBy({flowtempId: flowtempId}).then(response => {
          this.nodeOptions = response.data;
          // console.log(this.nodeOptions);
        });
        this.open = true;
        this.title = "修改流程节点";
      });
    },
    //条件查询
    handleCon(row) {
      this.flowtempnodeRow = row;
      // console.log(this.flowtempnodeRow);
      this.nodeId = row.id
      listFlowconditions({nodeId: row.id, flowtempid: row.flowtempId}).then(response => {
        this.conData = response.rows;
        console.log(this.conData);
        this.openCon = true;
      });
    },
    //条件新增按钮操作
    conditionsadd() {
      this.resetCon();
      this.formCon.nodeId = this.flowtempnodeRow.id;
      this.formCon.flowtempId = this.flowtempnodeRow.flowtempId;
      getFlowtempnodeBy({flowtempId: this.flowtempnodeRow.flowtempId}).then(response => {
        this.nodeOptions = response.data;
      });
      getDicts(this.flowtempnodeRow.busistatdick).then(response => {
        this.statusOptions = response.data;
      });
      this.openEditCon = true;
    },
    //条件修改按钮操作
    handleUpdateCon(row) {
      const id = row.id || this.ids
      getFlowconditions(id).then(response => {
        this.formCon = response.data;
        console.log(this.formCon);
        // console.log(response.data)
        if (this.formCon.issendoa != null && this.formCon.issendoa != "") {
          this.formCon.issendoa = this.formCon.issendoa.toString();
        }
        getFlowtempnodeBy({flowtempId: this.formCon.flowtempid}).then(response => {
          this.nodeOptions = response.data;
          // console.log(this.nodeOptions);
        });
        getDicts(this.formCon.busistatdick).then(response => {
          this.statusOptions = response.data;
        });

        this.openEditCon = true;
      });
    },
    // 取消按钮
    cancelCon() {
      this.openEditCon = false;
      this.resetCon();
    },
    /** 条件提交按钮 */
    submitFormCon() {
      this.$refs["formCon"].validate(valid => {
        if (valid) {
          // console.log(this.formCon);
          if (this.formCon.id != null) {

            updateFlowconditions(this.formCon).then(response => {
              console.log(this.formCon);
              this.msgSuccess("修改成功");
              this.openEditCon = false;
              listFlowconditions({nodeId: this.nodeId, flowtempid: this.flowtempId}).then(response => {
                this.conData = response.rows;
              });
            });
          } else {
            this.formCon.flowtempid = this.formCon.flowtempId;
            addFlowconditions(this.formCon).then(response => {
              console.log(this.formCon);
              this.msgSuccess("新增成功");
              this.openEditCon = false;
              listFlowconditions({nodeId: this.nodeId, flowtempid: this.flowtempId}).then(response => {
                this.conData = response.rows;
              });
            });
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // console.log(this.from);
          //  this.form.annex = this.form.annex.join(",");
          //  this.form.supervisor = this.form.supervisor.join(",");

          // if(this.form.annex != null && this.form.annex != ""){
          //   this.form.annex = this.form.annex.join(",");
          // }else{
          //   this.form.annex = ""
          // }

          // if(this.form.supervisor != null && this.form.supervisor != ""){
          // this.form.supervisor = this.form.supervisor.join(",");
          // }else{
          //   this.form.supervisor = ""
          // }
          // console.log("传入参数"+this.form+ "参数")
          if (this.form.id != null) {
            this.form.approvalType = this.form.approvalType - 0;

            this.form.flowtempid = this.form.flowtempId + '';
            // console.log(this.from);
            let postData = {
              id: this.form.id,
              flowtempId: this.form.flowtempId + '',
              name: this.form.name,
              ccPerm: this.form.ccPerm,
              sort: this.form.sort,
              operate: this.form.operate,
              permission: this.form.permission,
              flowStat: this.form.flowStat,
              flowNextStat: this.form.flowNextStat,
              nextNodeId: this.form.nextNodeId,
              nodeType: this.form.nodeType,
              flag: this.form.flag,
              isSendOa: this.form.isSendOa,
              repeatFlag: this.form.repeatFlag,
              refuseFlag: this.form.refuseFlag,
              timeLimit: this.form.timeLimit,
              remindRule: this.form.remindRule,
              operation: this.form.operation,
              approvalType: this.form.approvalType,
              branchiids: this.form.branchiids,
              remark: this.form.remark,
              annex: this.form.annex,
            };
            console.log(postData);
            updateFlowtempnode(postData).then(response => {
              // console.log(this.form);
              // console.log(postData);
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFlowtempnode(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const guids = row.id || this.ids;
      this.$confirm('是否确认删除该数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delFlowtempnode(guids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 删除按钮操作 */
    handleDeleteCon(row) {
      const id = row.id || this.ids;
      this.$confirm('是否确认删除该数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delFlowconditions(id);
      }).then(() => {
        listFlowconditions({nodeId: this.nodeId, flowtempid: this.flowtempId}).then(response => {
          this.conData = response.rows;
        });
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有流程节点数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportFlowtempnode(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    },
    /** 导出按钮操作 */
    handleRefresh() {
      this.$confirm('是否确认重新加载流程配置?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return allNeedReload();
      }).then(response => {
        this.getList();
        this.msgSuccess("操作成功");
      })
    }
  }
};
</script>
